//
//  LongerRentalAddController.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/6/29.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "LongerRentalAddController.h"
#import "TempletThirteenTableViewCell.h"
#import "LongerRentalBillCell.h"
#import "LongerRentalBillCountCell.h"
#import <BRPickerView/BRPickerView.h>

@interface LongerRentalAddController()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) CedarButton *comfirmBtn;
@property (nonatomic,strong) UILabel *titleLblFirst;
@property (nonatomic,strong) UILabel *titleLblSecond;

@end

@implementation LongerRentalAddController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加长租车";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.view);
    }];
    
    [self.tableView addSubview:self.comfirmBtn];
    [self.comfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-60);
        make.left.mas_equalTo(self.view).mas_offset(kMarginOffsetX);
        make.right.mas_equalTo(self.view).mas_offset(-kMarginOffsetX);
        make.height.mas_offset(40);
    }];
}

-(void)makeDatePicker {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMDHM;
    datePickerView.title = @"选择开始时间";
    datePickerView.selectDate = [NSDate br_setYear:2020 month:06 day:30];
    datePickerView.minDate = [NSDate br_setYear:1949 month:3 day:12];
    datePickerView.maxDate = [NSDate br_setYear:2022 month:06 day:30];
    datePickerView.isAutoSelect = YES;
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        NSLog(@"选择的值：%@", selectValue);
    };
    [datePickerView show];

}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 40.00f;
    }else {
        return 20.00f;
    }
}

//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    if (section == 0) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblFirst];
        [self.titleLblFirst mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }else{
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblSecond];
        [self.titleLblSecond mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TempletThirteenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TempletThirteenTableViewCellIdentifier"];
    if (indexPath.section == 0) {
         if (indexPath.row == 0) {
             cell.btnPlaceHolder = @"请选择品牌车系 ";
             [cell updateTitle:@"车牌号"];
           }else if (indexPath.row == 1) {
               cell.btnPlaceHolder = @"请选择车型名称";
               [cell updateTitle:@"车型名称"];

               
           }else if (indexPath.row == 2) {
               cell.btnPlaceHolder = @"请选择承租方名称";
               [cell updateTitle:@"承租方"];

               
           }else if (indexPath.row == 3) {
               cell.btnPlaceHolder = @"请选择开始时间";
               [cell updateTitle:@"开始时间"];
               @weakify(self)
               cell.chooseBtn.clickEvent = ^{
                   @strongify(self)
                   [self makeDatePicker];
               };

               
           }else if (indexPath.row == 4) {
               cell.btnPlaceHolder = @"请选择结束时间";
               [cell updateTitle:@"结束时间"];
               cell.chooseBtn.clickEvent = ^{
                   [self makeDatePicker];
               };
           }

    }else {
        if (indexPath.row == 0) {
            LongerRentalBillCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LongerRentalBillCellIdentifier"];
            return cell;
            
        }else if (indexPath.row == 1) {
            LongerRentalBillCountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LongerRentalBillCountCelIdentifier"];
            cell.placeholder = @"请输入金额";
            
            return cell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     return 64;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return   2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 5;
    }else {
        return 2;
    }
    return 0;
}


- (CedarButton *)comfirmBtn{
    if (!_comfirmBtn){
        _comfirmBtn =  [CedarButton buttonWithTextForGradientForCommomn:@"确认" radius:YES];
        @weakify(self)
        _comfirmBtn.clickEvent = ^{
            @strongify(self)
        };
    }
    return _comfirmBtn;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UIConfigure tableViewFromFactory];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 64;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        [_tableView registerClass:[TempletThirteenTableViewCell class] forCellReuseIdentifier:@"TempletThirteenTableViewCellIdentifier"];
        [_tableView registerClass:[LongerRentalBillCell class] forCellReuseIdentifier:@"LongerRentalBillCellIdentifier"];
        [_tableView registerClass:[LongerRentalBillCountCell class] forCellReuseIdentifier:@"LongerRentalBillCountCelIdentifier"];


    }
    return _tableView;
}

MACRO_UILabelWithPFCGFont(titleLblFirst,@"基本信息",kGrayColor,15)
MACRO_UILabelWithPFCGFont(titleLblSecond,@" ",kGrayColor,15)

@end
